﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HPortal.Lib;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;

namespace HPortal
{
    public partial class Default1 : System.Web.UI.Page
    {
        protected string CenterSourceFile = HtmlHelper.GetRequestString("Url", null);
        protected int ChannelID = HtmlHelper.GetIdFromRequestString("ChannelID", -1);
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "Vụ Khoa học Công nghệ & Môi trường";
            if (this.ChannelID == -1)
            {
                try
                {
                    bool isEN = (bool)System.Web.HttpContext.Current.Session["isEN"];
                    if (isEN)
                        ChannelID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["rootChannelIDEN"].ToString());
                    else
                        ChannelID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["rootChannelIDVN"].ToString());
                }
                catch (Exception ex)
                {
                    ChannelID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["rootChannelIDVN"].ToString());
                }
            }

            if (CenterSourceFile != null)
            {
                int panelID = HtmlHelper.GetIdFromRequestString("PanelID", -1);
                PanelControl pn = (PanelControl)LoadControl(CenterSourceFile);
                pn.PanelID = panelID;
                this.MainThreads.Controls.Add(pn);
                //CenterCollumn.Width = "600px";
            }


            SqlDataReader dr = DatabaseHelper.SelectReader("exec getPanelList " + ChannelID);
            while (dr.Read())
            {
                PanelControl pn = (PanelControl)LoadControl("Panel.ascx");
                pn.PanelID = int.Parse(dr["PanelID"].ToString());
                switch ((int)dr["CellID"])
                {
                    case (int)CellEnum.TopCell:
                        this.TopRow.Controls.Add(pn);
                        break;
                    //case (int)CellEnum.LeftCell:
                    //    this.LeftCollumn.Controls.Add(pn);
                    //    break;
                    case (int)CellEnum.CenterCell:
                        if (this.CenterSourceFile == null)
                            this.MainThreads.Controls.Add(pn);
                        break;
                    case (int)CellEnum.RightCell:
                        this.FooterThreads.Controls.Add(pn);
                        break;
                    case (int)CellEnum.BottomCell:
                        this.Bottom.Controls.Add(pn);
                        break;
                }
            }
            dr.Close();
        }
    }
}